﻿using Microsoft.Extensions.Logging;
using Simple.Framework.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Simple.Tools;

/*********************************************************
 * 命名空间 SimpleNet.example.Inter
 * 接口名称 ExtPretty
 * 开发人员：ADMIN
 * 创建时间：2023/12/13 15:00:14
 * 描述说明：
 * 更改历史：
 * 
 * *******************************************************/
namespace SimpleNet.example.Inter
{
	internal class ExtPretty : Pretty, IPretty
	{

		public override void Initalization()
		{
			HostConfiguration[] cfg = configution.GetValue<HostConfiguration[]>("PrettyServices");
			if (ToolSimpleCheck.IsNullOrEmpty(cfg))
			{
				logger.LogError("请配置配置服务端口和地址!");
				return;
			}
			IPEndPoint endPoint = new IPEndPoint(cfg[0].GetIpAddress(), cfg[0].Port);
			pretty = new Socket(AddressFamily.InterNetwork, cfg[0].SocketType, cfg[0].ProtocolType);
			pretty.Bind(endPoint);
			pretty.Listen(cfg[0].Backlog);

			logger.LogInformation($"开始监听{cfg[0].IpAddress}:{cfg[0].Port}");
			logger.LogInformation("服务器启动成功!");
		}

		public override void Accept()
		{
			base.Accept();
		}

		public override void Start()
		{
			base.Start();
		}
	}
}
